/*
 * CS_DUNGEON_REBIRTH_ZEN.cpp
 *
 *  Created on: 2013. 6. 14.
 *      Author: the2
 */


#include "../../User.h"
#include "dungeon.h"

#include "../../NLogic/Space.h"
#include "../../NLogic/VirtualCurrency.h"
#include "../../NLogic/Battle.h"
#include "../../NResource/Static.h"

namespace ProjectZ { namespace NCommand { namespace NDungeon {

void CS_DUNGEON_REBIRTH_ZEN::OnExecute(User * pUser, ::Network::Packet * pPacket)
{
	/*
	 * /// 젠소모 처리
	CS_DUNGEON_REBIRTH_ZEN	0x0827
	{

	}

	/// 당사자 유저에게 전송
	SC_DUNGEON_REBIRTH_ZEN	0x0828
	{
		s16 s16ack;
		u32 u32gur_zen;
	}


	/// 부활처리
	SC_DUNGEON_REBIRTH	0x082A
	{
		s16 s16ack;
		u32 u32gid;
	}
	 */
	NLogic::Space * pSpace = pUser->GetSpace();
	if (NULL == pSpace)
	{
		DEBUGLOG("CS_DUNGEON_REBIRTH_ZEN NULL == pSpace");
		return;
	}

	if (false == pSpace->IsDungeon())
	{
		DEBUGLOG("CS_DUNGEON_REBIRTH_ZEN space Type is not dungeon");
		return;
	}

	PREPARE_PACKET;

	NResource::VCResource::Flyweight * pFly =
			NResource::Static::InstancePtr()->GetVCRef()->GetFly(EM_VCINDEX_DUNGEON_REBIRTH);

	if (NULL == pFly)
	{
		PROCESSLOG("CS_DUNGEON_REBIRTH_ZEN : pFly is NULL!!");
		return;
	}

	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();

	if( pUser->GetVirtualCurrency()->GetZen() < (pFly->_VC_PRICE * -1) )
	{
//		pUser->player_info.HP = pUser->player_info.HP_MAX;
		pUser->GetBattle()->GetData().HP = pUser->GetBattle()->GetData().HP_MAX;
		* pAck << static_cast<int16_t>(ACK_NOT_ENOUGH_ZEN) << pUser->GetVirtualCurrency()->GetZen();
		pAck->MakePacket(CMD_SC_DUNGEON_REBIRTH_ZEN);
		pUser->Send(pAck);

		return;
	}

//	pUser->player_info.HP = pUser->player_info.HP_MAX;
//	pUser->player_info.SP = pUser->player_info.SP_MAX;

	pUser->GetBattle()->GetData().HP = pUser->GetBattle()->GetData().HP_MAX;
	pUser->GetBattle()->GetData().SP = pUser->GetBattle()->GetData().SP_MAX;

	DEBUGLOG("CS_DUNGEON_REBIRTH_ZEN hp : %d", pUser->GetBattle()->GetData().HP);

	// VC 처리
	NLogic::NFunction::VCProcess(pUser, EM_VCINDEX_DUNGEON_REBIRTH);

	* pAck << static_cast<int16_t>(ACK_OK) << pUser->GetVirtualCurrency()->GetZen();
	pAck->MakePacket(CMD_SC_DUNGEON_REBIRTH_ZEN);
	pUser->Send(pAck);

	::Network::Packet * pNoti = ::Network::GETPACKETPOOL()->SEND_NEW();
	* pNoti << static_cast<int16_t>(ACK_OK) << pUser->GetUserSeq();
	pNoti->MakePacket(CMD_SN_DUNGEON_REBIRTH);
	pSpace->SendAll(pNoti);
}

} /*NDungeon*/ } /*NCommand*/ } /*ProjectZ*/

